package com.eastfair.venueservice.controller;

import com.eastfair.annotation.annotation.log.SysLog;
import com.eastfair.venueservice.dto.*;
import com.eastfair.venueservice.entity.ExhibitionSettlementRefund;
import com.eastfair.venueservice.service.ExhibitionSettlementRefundService;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.eastfair.boot.controller.SuperController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.echo.core.EchoService;
import com.eastfair.core.base.R;
import com.eastfair.venueservice.vo.ExhibitionSettlementRefundVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import com.eastfair.annotation.annotation.security.PreAuth;

import com.eastfair.boot.request.PageParams;
import com.eastfair.core.context.ContextUtil;
import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 前端控制器
 * 结算退款记录
 * </p>
 *
 * @author linan
 * @date 2023-02-01
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/exhibitionSettlementRefund")
@Api(value = "ExhibitionSettlementRefund", tags = "结算退款记录")
@PreAuth(replace = "venueservice:exhibitionSettlementRefund:")
public class ExhibitionSettlementRefundController extends SuperController<ExhibitionSettlementRefundService, Long, ExhibitionSettlementRefund, ExhibitionSettlementRefundPageQuery, ExhibitionSettlementRefundSaveDTO, ExhibitionSettlementRefundUpdateDTO> {

    @Autowired
    private EchoService echoService;

    @Override
    public void handlerResult(IPage<ExhibitionSettlementRefund> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }
    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<ExhibitionSettlementRefund> exhibitionSettlementRefundList = list.stream().map((map) -> {
            ExhibitionSettlementRefund exhibitionSettlementRefund = ExhibitionSettlementRefund.builder().build();
            //TODO 请在这里完成转换
            return exhibitionSettlementRefund;
        }).collect(Collectors.toList());

        return R.success(baseService.saveBatch(exhibitionSettlementRefundList));
    }



    /**
     * 处理参数
     *
     * @param params 分页参数
     */
    @Override
    public void handlerQueryParams(PageParams<ExhibitionSettlementRefundPageQuery> params) {
        ExhibitionSettlementRefundPageQuery pageQuery = params.getModel();

    }


    /**
     * 保存结算退款记录.
     *
     * @param dto the dto
     * @return the r
     */
    @ApiOperation("保存结算退款记录.")
    @SysLog("保存结算退款记录")
    @PostMapping("/saveRefundRecord")
    public R<Boolean> saveRefundRecord(@RequestBody ExhibitionSettlementRefundDTO dto) {
        log.info("saveRefundRecord - 保存结算退款记录., dto={}", dto);
        return R.success(baseService.saveRefundRecord(dto));
    }

    /**
     * 更新结算退款记录.
     *
     * @param dto the dto
     * @return the r
     */
    @ApiOperation("更新结算退款记录.")
    @SysLog("更新结算退款记录")
    @PostMapping("/updateRefundRecord")
    public R<Boolean> updateRefundRecord(@RequestBody ExhibitionSettlementRefundDTO dto) {
        log.info("updateRefundRecord - 更新结算开票记录., dto={}", dto);
        return R.success(baseService.updateRefundRecord(dto));
    }

    /**
     * 查询结算退款记录.
     *
     * @param dto the dto
     * @return the r
     */
    @ApiOperation("查询结算退款记录.")
    @PostMapping("/queryRefundRecord")
    public R<ExhibitionSettlementRefundVO> queryRefundRecord(@RequestBody ExhibitionSettlementRefundDTO dto) {
        log.info("queryRefundRecord - 查询结算退款记录., dto={}", dto);
        return R.success(baseService.queryRefundRecord(dto));
    }

}
